//
//  CRSpaceHeadView.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/23.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRSpaceHeadView.h"

@interface CRSpaceHeadView ()



/**
 *  发送按钮
 */
@property (nonatomic, strong) UIButton *sendButton;

@end

@implementation CRSpaceHeadView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        // 添加输入框和发送按钮
        self.inputText = [[UITextField alloc] init];
        self.inputText.placeholder = @"请发表动态...";
        self.inputText.layer.borderWidth = 1;
        self.inputText.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor colorWithRed:0.871 green:1.000 blue:0.715 alpha:1.000]);
        self.inputText.borderStyle = UITextBorderStyleRoundedRect;
        
    
        
  
        self.sendButton = [[UIButton alloc] init];
        self.sendButton.titleLabel.font = [UIFont boldSystemFontOfSize:11];
        [self.sendButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self.sendButton setBackgroundImage:[UIImage imageNamed:@"iconfont-tupian"] forState:UIControlStateNormal];
        [self.sendButton addTarget:self action:@selector(clickSendButton:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:self.inputText];
        [self addSubview:self.sendButton];
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 计算子控件frame
    CGFloat inputX = 3;
    CGFloat inputY = 0;
    CGFloat inputW = self.frame.size.width - 30 - 6;
    CGFloat inputH = self.frame.size.height;
    self.inputText.frame = CGRectMake(inputX, inputY, inputW, inputH);
    
    // 发送按钮的frame
    CGFloat buttonX = CGRectGetMaxX(self.inputText.frame);
    CGFloat buttonW = 30;
    CGFloat buttonH = inputH;
    self.sendButton.frame = CGRectMake(buttonX, 0, buttonW, buttonH);
    
    
}

// 代理方法
- (void)clickSendButton:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(spaceHeadViewDidClickSendButton:andSendText:)]) {
        [self.delegate spaceHeadViewDidClickSendButton:button andSendText:self.inputText.text];
    }
}



@end
















